import tkinter as tk
from tkinter import messagebox
from db import db
from RegisterFunction import RegisterFunction

class RegistertPage(tk.Frame):
    #注册页面
    def __init__(self, master, fram):
        super().__init__(master)
        self.root = master
        self.fram = fram
        # 获取账号和密码的值
        self.username = tk.StringVar()
        self.password = tk.StringVar()

        self.frame = tk.Frame(self.root)
        self.frame.pack()
        # 构造功能类
        self.insert_function()
        # 注册账号页面布局
        tk.Label(self.frame, text="欢迎员工登录注册理系统", anchor="center", fg="red").grid(row=0, column=1, pady=20, columnspan=2)
        # 账号文本框的布局
        tk.Label(self.frame, text="账号: ").grid(row=1, column=1, pady=10)
        self.e1 = tk.Entry(self.frame, textvariable=self.username)
        self.e1.grid(row=1, column=2, pady=10)

        tk.Label(self.frame, text="密码: ").grid(row=2, column=1, pady=10)
        self.e2 = tk.Entry(self.frame, textvariable=self.password)
        self.e2.grid(row=2, column=2, pady=10)

        tk.Button(self.frame, text="注册", command=self.my_register).grid(row=3, column=1, pady=10, sticky='e')
        tk.Button(self.frame, text="返回", command=self.my_exit).grid(row=3, column=2, pady=10, sticky='e')

    # 注册按钮功能方法
    def insert_function(self):
        self.func = RegisterFunction(self.frame, self.fram)

    # 调用按钮功能
    def my_register(self):
        self.username = self.e1.get()
        self.password = self.e2.get()
        self.func.function_register(self.username, self.password)


    # 调用返回按钮功能
    def my_exit(self):
        self.func.function_exit()
